const CryptoJS = require("crypto");
function main(item) {
    const id = item.id || 'cctv1';
    const n = {
        'cctv1': '11200132825562653886',
        'cctv2': '12030532124776958103',
        'cctv4': '10620168294224708952',
        'cctv7': '8516529981177953694',
        'cctv9': '7252237247689203957',
        'cctv10': '14589146016461298119',
        'cctv12': '13180385922471124325',
        'cctv13': '16265686808730585228',
        'cctv17': '4496917190172866934',
        'cctv4k': '2127841942201075403',
    };
    const articleId = n[id];
    const t = Math.floor(Date.now() / 1000);
    const sail = ku9.md5(`articleId=${articleId}&scene_type=6`);
    const w = `&&&20000009&${sail}&${t}&emas.feed.article.live.detail&1.0.0&&&&&`;
    const k = "emasgatewayh5";
    const sign = CryptoJS.HmacSHA256(w, k).toString();
    const url = `https://emas-api.cctvnews.cctv.com/h5/emas.feed.article.live.detail/1.0.0?articleId=${articleId}&scene_type=6`;
    const client_id = ku9.md5(t.toString());
    const headers = {
        'cookieuid': client_id,
        'from-client': 'h5',
        'referer': 'https://m-live.cctvnews.cctv.com/',
        'x-emas-gw-appkey': '20000009',
        'x-emas-gw-pv': '6.1',
        'x-emas-gw-sign': sign,
        'x-emas-gw-t': t,
        'x-req-ts': t * 1000
    };
    const res = ku9.get(url, headers);
    const responseData = JSON.parse(res);
    const decodedData = JSON.parse(ku9.decodeBase64(responseData.response));
    const data = decodedData.data;
    const authUrl = data.live_room.liveCameraList[0].pullUrlList[0].authResultUrl[0].authUrl;
    const key = data.dk.substring(0, 8) + t.toString().substring(t.toString().length - 8);
    const iv = data.dk.substring(data.dk.length - 8) + t.toString().substring(0, 8);
    const decrypted = ku9.opensslDecrypt(authUrl, "AES-128-CBC", key, 0, iv);
    return { url: decrypted };
}